<?php
class ChucvucbsController extends AppController {

	var $name = 'Chucvucbs';

	function index() {
		$this->Chucvucb->recursive = 0;
		$this->set('chucvucbs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid chucvucb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('chucvucb', $this->Chucvucb->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Chucvucb->create();
			if ($this->Chucvucb->save($this->data)) {
				$this->Session->setFlash(__('The chucvucb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The chucvucb could not be saved. Please, try again.', true));
			}
		}
		$canbos = $this->Chucvucb->Canbo->find('list');
		$chucvs = $this->Chucvucb->Chucv->find('list');
		$this->set(compact('canbos', 'chucvs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid chucvucb', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Chucvucb->save($this->data)) {
				$this->Session->setFlash(__('The chucvucb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The chucvucb could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Chucvucb->read(null, $id);
		}
		$canbos = $this->Chucvucb->Canbo->find('list');
		$chucvs = $this->Chucvucb->Chucv->find('list');
		$this->set(compact('canbos', 'chucvs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for chucvucb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Chucvucb->delete($id)) {
			$this->Session->setFlash(__('Thông tin đã xóa', true),'success');
			$this->redirect(array('controller'=>'z1chucvucbs','action'=>'index'));
		}
		$this->Session->setFlash(__('Thông tin không thể xóa', true),'error');
		$this->redirect(array('controller'=>'z1chucvucbs','action' => 'index'));
	}
}
